#include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    int n = 0;
    cin >> n;
    vector<int> arr(n + 1);
    auto f = arr; // 1到i第一大
    auto g = arr; // 1到i第二大
    for(int i = 1; i <= n; ++i)
    {
        cin >> arr[i];
    }
    
    f[1] = arr[1];
    for(int i = 1; i <= n; ++i)
    {
        int x = arr[i];
        f[i] = max(f[i - 1], x);
        if(x >= f[i - 1])
            g[i] = f[i - 1];
        else if(x >= g[i - 1])
            g[i] = x;
        else 
            g[i] = g[i - 1];
    }
    int q = 0;
    cin >> q;
    while(q--)
    {
        int n = 0;
        cin >> n;
        cout << g[n] << endl;
    }
    return 0;
}